home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / MORETXT.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  3KB  |  213 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. /*
  12.  * drawgrid
  13.  *
  14.  *    draw a grid in the middle of the screen
  15.  */
  16. void
  17. drawgrid()
  18. {
  19.     float    x;
  20.     int    i;
  21.  
  22.     color(GREEN);
  23.  
  24.     rect(0.1, 0.4, 0.9, 0.6);
  25.  
  26.     x = 0.2;
  27.     for (i = 0; i < 8; i++) {
  28.         move2(x, 0.4);
  29.         draw2(x, 0.6);
  30.         x += 0.1;
  31.     }
  32.     move2(0.1, 0.5);
  33.     draw2(0.9, 0.5);
  34.  
  35.     color(YELLOW);
  36. }
  37.  
  38. /*
  39.  * demonstrate some more features of text
  40.  */
  41. main(argc, argv)
  42.     int    argc;
  43.     char    **argv;
  44. {
  45.     int    i;
  46.     float    x;
  47.     short    val;
  48.     
  49.     winopen("moretxt");
  50.  
  51.     unqdevice(INPUTCHANGE);
  52.     qdevice(KEYBD);
  53.  
  54.     if (argc == 2)
  55.         hfont(argv[1]);
  56.     else
  57.         hfont("futura.l");
  58.  
  59.     htextsize(0.05, 0.05);
  60.  
  61.     ortho2(0.0, 1.0, 0.0, 1.0);
  62.  
  63.     color(BLACK);
  64.     clear();
  65.  
  66.     drawgrid();
  67.  
  68.     /*
  69.      * show some scaled text on the grid (In the bottom part)
  70.      */
  71.     hboxtext(0.1, 0.4, 0.8, 0.1, "{This is Some text] | $");
  72.  
  73.     qread(&val);
  74.  
  75.     color(BLACK);
  76.     clear();
  77.  
  78.     drawgrid();
  79.  
  80.     /*
  81.      * centertext causes text to be centered around the current graphics
  82.      * position this is especially usefull if you want your text to come
  83.      * out centered on a line, or a character to be centered on a point
  84.      * in a graph. A non-zero argument turns centertext on.
  85.      *
  86.      * show a string centered on the center line
  87.      */
  88.     hcentertext(1);
  89.  
  90.     hboxtext(0.5, 0.5, 0.8, 0.1, "{This is Some Centered text] | $");
  91.  
  92.     /*
  93.      * turn centertext off. We use an argument with the value zero.
  94.      */
  95.     hcentertext(0);
  96.  
  97.     qread(&val);
  98.  
  99.     color(BLACK);
  100.     clear();
  101.  
  102.     /*
  103.      * rotate the grid so that it is the same angle as the text after
  104.      * textang for text ang.
  105.      */
  106.     pushmatrix();
  107.         translate(0.5, 0.5, 0.0);
  108.         rotate(900, 'z');
  109.         translate(-0.5, -0.5, 0.0);
  110.  
  111.         drawgrid();
  112.     popmatrix();
  113.  
  114.     /*
  115.      * turn on centered text again
  116.      */
  117.     hcentertext(1);
  118.  
  119.     /*
  120.      * set the angle to 90.
  121.      */
  122.     htextang(90.0);
  123.  
  124.     /*
  125.      * draw the string
  126.      */
  127.     hboxtext(0.5, 0.5, 0.8, 0.1, "{This is Some Rotated Centered text] | $");
  128.  
  129.     /*
  130.      * turn off center text
  131.      */
  132.     hcentertext(0);
  133.  
  134.     /*
  135.      * set text angle back to 90
  136.      */
  137.     htextang(0.0);
  138.  
  139.     qread(&val);
  140.  
  141.     color(BLACK);
  142.     clear();
  143.  
  144.     drawgrid();
  145.  
  146.     /*
  147.      * as all the software fonts are proportionally spaced we use
  148.      * the fixedwidth call to make each character take the same amount
  149.      * of horizontal space. As with centertext this is done by passing
  150.      * fixedwidth a non-zero argument.
  151.      */
  152.     hfixedwidth(1);
  153.  
  154.     hboxtext(0.1, 0.5, 0.8, 0.1, "{This is Some Fixedwidth text] | $");
  155.  
  156.     qread(&val);
  157.  
  158.     color(BLACK);
  159.     clear();
  160.  
  161.     drawgrid();
  162.  
  163.     /*
  164.      * now try centered and fixewidth at the same time
  165.      */
  166.     hcentertext(1);
  167.  
  168.     color(RED);
  169.     move2(0.5, 0.5);
  170.     hcharstr("{This is Some Cent.Fixedwidth text] | $");
  171.  
  172.     hcentertext(0);
  173.     
  174.     qread(&val);
  175.     color(BLACK);
  176.     clear();
  177.  
  178.     drawgrid();
  179.  
  180.     color(RED);
  181.     move2(0.9, 0.4);
  182.     hrightjustify(1);
  183.     hfixedwidth(0);
  184.     hcharstr("{This is Some Right Justified text] | $");
  185.  
  186.     qread(&val);
  187.     color(BLACK);
  188.     clear();
  189.  
  190.     drawgrid();
  191.  
  192.     /*
  193.      * scale the text so tha a character is the size of a box in
  194.      * the grid.
  195.      */
  196.     hboxfit(0.8, 0.1, 8);
  197.  
  198.     hfixedwidth(1);
  199.     /*
  200.      * draw the two strings fixedwidth (it is still turned on)
  201.      */
  202.     hleftjustify(1);
  203.     move2(0.1, 0.4);
  204.     hcharstr("ABCDefgh");
  205.  
  206.     move2(0.1, 0.5);
  207.     hcharstr("IJKLmnop");
  208.  
  209.     qread(&val);
  210.  
  211.     gexit();
  212. }
  213.